﻿/****************************************************************************
*                                                                           *
* Copyright (c) Ionescu M. Marius. All rights reserved(2010).               *
*                                                                           *
****************************************************************************/

using System;

/// <summary>
/// String Extensions
/// </summary>
public static class StringExtensions
{
	/// <summary>
	/// Replace <code>\r\n</code> with <code>&lt;br /&gt;</code>
	/// </summary>
	public static string ReplaceNewLineWithBR(this string s)
	{
		return s.Replace("\r\n", "<br />").Replace("\n", "<br />");
	}

	public static string ReplaceApostrophe(this string s)
	{
		return s.Replace("'", @"\'");
	}

	public static string Join(this System.Collections.Generic.List<string> list, string separator)
	{
		return string.Join(separator, list.ToArray());
	}
	private static void TestJoin()
	{
		System.Collections.Generic.List<string> dummy = new System.Collections.Generic.List<string>();
		dummy.AddRange(new string[] { "one", "two", "three" });
		string result = dummy.Join(", ");
	}

	public static string SqlEscape(this string s)
	{
		return s.Replace("'", "''");
	}
	public static string GetSqlEscapedString(this System.Web.UI.WebControls.TextBox source)
	{
		return source.Text.SqlEscape();
	}

	public static string RemoveHtml(this string text)
	{
		return text.Replace("<br/>", " ").Replace("<br />", " ")
			.Replace("<i>", "/").Replace("</i>", "/")
			.Replace("<u>", "_").Replace("</u>", "_")
			.Replace("<b>", "*").Replace("</b>", "*");
	}
}
